package com.control.mbtc.fragments.account;


import android.content.Context;
import androidx.fragment.app.Fragment;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.control.mbtc.R;
import com.zzyd.common.app.PersenterFragment;
import com.zzyd.factory.account.LoginContract;
import com.zzyd.factory.account.LoginPresenter;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class LoginFragment extends PersenterFragment<LoginContract.Persenter> implements LoginContract.View{

    private TargView targView;
    @BindView(R.id.edit_name)
    EditText edit_name;
    @BindView(R.id.edit_pwd)
    EditText edit_pwd;
    @BindView(R.id.btn_login)
    Button btn_login;


    public LoginFragment() {
        // Required empty public constructor
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        /**
         * fragment回调接口赋值
         */
        targView= (TargView) context;
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.fragment_login;
    }

    @Override
    protected void initWidget(View root) {
        super.initWidget(root);
//        EventBus.getDefault().register(this);
    }

    @Override
    protected LoginContract.Persenter initPersenter() {
        return new LoginPresenter(this);
    }

    @Override
    public void loginSuccess() {
//        EventBus.getDefault().post("success");
    }

    @OnClick(R.id.btn_login)
    void loginClick(){
        Toast.makeText(getContext(), "123", Toast.LENGTH_SHORT).show();
        mPersenter.login(edit_name.getText().toString(),edit_pwd.getText().toString());
    }
    @OnClick(R.id.txt_go_register)
    void showRegister(){
        targView.viewTarg();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    void eventSuccess(String msg){
        Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();

    }

}
